package com.koron.tool.controller;

import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.tool.bean.DictData;
import com.koron.tool.bean.DictItem;
import com.koron.tool.service.DictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Author: liaodf
 * @Date: 2021/10/27 10:58
 */
@Slf4j
@Api(tags = "数据字典管理")
@RestController
@RequestMapping("/dict")
public class DictDataController {


    @Autowired
    private DictDataService service;

    /**
     * 获取数据字典数据
     *
     * @param user 当前用户
     * @return Resposnse对象
     * @version 1.0
     * @see Response
     */
    @ApiOperation(value = "获取数据字典数据")
    @GetMapping("/getDict")
    public Response useRecordList(@CasUser @ApiIgnore EamUser user,String code) {
        return ADOConnection.runTask(user.getCurrDs(), service, "getDict", Response.class,code);
    }

    /**
     * 保存数据字典
     *
     * @param user 当前用户
     * @return Resposnse对象
     * @version 1.0
     * @see Response
     */
    @ApiOperation(value = "保存数据字典")
    @PostMapping("/save")
    public Response save(@CasUser @ApiIgnore EamUser user,@RequestBody DictData dictData) {
        return ADOConnection.runTask(user.getCurrDs(), service, "save", Response.class,user,dictData);
    }

    /**
     * 保存数据字典项
     *
     * @param user 当前用户
     * @return Resposnse对象
     * @version 1.0
     * @see Response
     */
    @ApiOperation(value = "保存数据字典项")
    @PostMapping("/saveItem")
    public Response saveItem(@CasUser @ApiIgnore EamUser user,@RequestBody DictItem dictItem) {
        return ADOConnection.runTask(user.getCurrDs(), service, "saveItem", Response.class,user,dictItem);
    }

    /**
     * 删除数据字典
     *
     * @param user 当前用户
     * @return Resposnse对象
     * @version 1.0
     * @see Response
     */
    @ApiOperation(value = "删除数据字典")
    @PostMapping("/delete")
    public Response delete(@CasUser @ApiIgnore EamUser user,String id) {
        return ADOConnection.runTask(user.getCurrDs(), service, "delete", Response.class,user,id);
    }

    /**
     * 删除数据字典项
     *
     * @param user 当前用户
     * @return Resposnse对象
     * @version 1.0
     * @see Response
     */
    @ApiOperation(value = "删除数据字典项")
    @PostMapping("/deleteItem")
    public Response deleteItem(@CasUser @ApiIgnore EamUser user,String id) {
        return ADOConnection.runTask(user.getCurrDs(), service, "deleteItem", Response.class,user,id);
    }

}
